import os

import pygame.image

from constants import layers


def get_layer(name, key="z"):
    layer = list(filter(lambda item: item.name == name, layers))
    if layer:
        layer = layer[0]
        if key:
            return getattr(layer, key)
        else:
            return layer
    return None


def load_files(path):
    _dict = {}
    for root, dirs, files in os.walk(path):
        for file in files:
            arr = str(file).split(".")
            del arr[len(arr) - 1]
            _dict["".join(arr)] = pygame.image.load(f"{path}{file}")
    return _dict
